package org.sczfdf.listener;

import org.apache.commons.io.monitor.FileAlterationListenerAdaptor;
import org.sczfdf.utils.GitUtil;
import org.sczfdf.utils.LogUtil;
import org.sczfdf.utils.WatchUtil;

import java.io.File;

public class FileListener extends FileAlterationListenerAdaptor {
    /**
     * File created Event.
     *
     * @param file The file created (ignored)
     */
    @Override
    public void onFileCreate(File file) {
        LogUtil.logInfo("创建文件: " + file.getAbsolutePath());
        GitUtil.pushAll();
        WatchUtil.executeOtherCommand();
    }

    /**
     * File changed Event.
     *
     * @param file The file changed (ignored)
     */
    @Override
    public void onFileChange(File file) {
        LogUtil.logInfo("修改文件: " + file.getAbsolutePath());
        GitUtil.pushAll();
        WatchUtil.executeOtherCommand();
    }

    /**
     * File deleted Event.
     *
     * @param file The file deleted (ignored)
     */
    @Override
    public void onFileDelete(File file) {
        LogUtil.logInfo("删除文件: " + file.getAbsolutePath());
        GitUtil.pushAll();
        WatchUtil.executeOtherCommand();
    }

}